package com.guigu.work.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.work.entity.TransportOrderTask;
import com.guigu.work.mapper.TransportOrderTaskMapper;
import com.guigu.work.service.TransportOrderTaskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 运单与运输任务关联表 服务实现类
 * </p>
 *
 * @author liAo
 * @since 2021-11-09
 */
@Service
@Transactional
public class TransportOrderTaskServiceImpl extends ServiceImpl<TransportOrderTaskMapper, TransportOrderTask> implements TransportOrderTaskService {

    /**
     * 根据运单ID或运输任务ID删除关系
     *
     * @param toId
     * @param ttId
     * @return
     */
    @Override
    public boolean deleteBytoIdOrttId(String toId, String ttId) {
        boolean b = false;
        LambdaQueryWrapper<TransportOrderTask> wrapper = new LambdaQueryWrapper();
        if (StringUtils.isNoneBlank(toId)) {
            wrapper.eq(TransportOrderTask::getTransportOrderId, toId);
            b = true;
        }
        if (StringUtils.isNoneBlank(ttId)) {
            wrapper.eq(TransportOrderTask::getTransportTaskId, ttId);
            b = true;
        }
        return b ? this.remove(wrapper) : false;
    }

    /**
     * 获取运单与运输任务关联关系列表
     *
     * @param toId
     * @param ttId
     * @return
     */
    @Override
    public List<TransportOrderTask> findAll(String toId, String ttId) {
        boolean b = false;
        LambdaQueryWrapper<TransportOrderTask> wrapper = new LambdaQueryWrapper();
        if (StringUtils.isNotBlank(toId)) {
            b = true;
            wrapper.eq(TransportOrderTask::getTransportOrderId, toId);
        }
        if (StringUtils.isNotBlank(ttId)) {
            b = true;
            wrapper.eq(TransportOrderTask::getTransportTaskId, ttId);
        }
        return b ? this.list(wrapper) : null;
    }
}
